<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
		    <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
		    <a onclick="close1()" class="mui-icon mui-icon-close mui-pull-left" style="color: red; margin-left: 3px;"></a>
		    
		    <a onclick="play1()" class="mui-icon mui-icon-videocam mui-pull-right"></a>
		    <h1 class="mui-title"></h1>
		</header>
		<script src="../js/mui.min.js"></script>
		<script src="../js/jQuery.js"></script>
		<script src="../js/common.js"></script>
		<script type="text/javascript">
			
			window.play1 = function(){
				homeWebView.evalJS("var href = location.href;var title = document.title;plus.webview.currentWebview().opener().evalJS(\"window.play('\"+href+\"')\")")
			}
			window.close1 = function(){
				plus.navigator.setUserAgent("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Mobile Safari/537.36");
				
				if(window.homeWebView && window.homeWebView.isVisible()){
					homeWebView.close("slide-out-right")	
				}
				if(window.embed && window.embed.isVisible()){
					homeWebView.close("slide-out-right")
				}
				
				plus.webview.currentWebview().close("slide-out-right")
			}
			window.play = function(href) {
				if(plus.webview.getWebviewById("play-web-view")) {
					return;
				}
				var user = getLoginUser();
				if(!user) {
					mui.toast("请先登陆!")
					return;
				}
				//查询会员权限
				var title = homeWebView.getTitle();
				var id = plus.webview.currentWebview()._id
				postServer({
					url: requestUrl("/app/appUser/isExpire"),
					success: function(result) {
						if(result.success) {
							//电脑useragent
							plus.navigator.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36')
							window.embed = plus.webview.create(requestUrl("/app/play?title=" + title + "&videoId=" + id + "&url=" + href), 'play-web-view', {
								additionalHttpHeaders: {
									"SESSION_APPUSER": JSON.stringify(user)
								},
								videoFullscreen: 'landscape-primary'
							});
							embed.show("slide-in-right");
						} else {
							alert(result.msg);
						}
					}
				})
			}
			mui.init()
			mui.plusReady(function() {
				plus.navigator.setUserAgent("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Mobile Safari/537.36");
				var _back = mui.back;
				mui.back = function() {
					//手机useragent
					plus.navigator.setUserAgent("Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Mobile Safari/537.36");
					if(window.embed && window.embed.isVisible()) {
						window.embed.close("slide-out-right")
					} else {
						window.homeWebView.canBack(function(e) {
							if(e.canBack) {
								window.homeWebView.back()
							} else {
								_back();
							}
							/* else {
															mui.confirm("是否确认退出" + plus.webview.currentWebview().label, "提示:", function(e) {
																if(e.index == 1) {
																	_back();
																	mui.toast("已退出" + plus.webview.currentWebview().label + "!")
																}
															})
														}*/
						})
					}
				}
				$(".mui-title").html(plus.webview.currentWebview().label)
				window.homeWebView = plus.webview.create(
					plus.webview.currentWebview().url, "test", {
						scrollIndicator: "none",
						backButtonAutoControl: "none",
						hardwareAccelerated:true,
						top:"44px",
						userSelect:false
					}
				);
				homeWebView.show();
				homeWebView.addEventListener('rendering', function(e) {
					if(window.loading) {
						window.loading.close();
					}
//					homeWebView.evalJS(plus.webview.currentWebview().script);
					//					homeWebView.evalJS("alert($('#pplive-player').length)")
					//					homeWebView.evalJS(plus.webview.currentWebview().script);
					//					homeWebView.evalJS("alert(1)");

				}, false);

//				homeWebView.addEventListener('loading', function(e) {
//					if(window.loading) {
//						window.loading.close();
//					} 
//					homeWebView.evalJS(plus.webview.currentWebview().script);
//				}, false);

//				homeWebView.addEventListener('touchstart', function(e) {
//					homeWebView.evalJS(plus.webview.currentWebview().script);
//				}, false);

//				homeWebView.listenResourceLoading({
//					match: '.*\\.(jpg|png|jpeg|bmp)\\b'
//				}, function(e) {
//					homeWebView.evalJS(plus.webview.currentWebview().script);
//				});

				//				homeWebView.overrideUrlLoading({
				//					//										match:"^http://m.iqiyi.com/v_19rr*$",
				//					//										mode: "reject" 
				//				}, function(event) {
				//					console.log(JSON.stringify(event));
				//					var url = event.url;
				//
				//					if(url.startsWith("http://www.skip.com")) {
				//						url = homeWebView.getURL();
				//						alert(url);
				//						alert(homeWebView.getTitle())
				//						homeWebView.evalJS("")
				//						//						alert(1)
				//						plus.navigator.setUserAgent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/63.0.3239.132 Safari/537.36')
				//						url = url.replace("http://m.iqiyi.com", "http://www.iqiyi.com");
				//						window.embed = plus.webview.create('http://17kyun.com/api.php?url=' + url, 'test', {
				//							additionalHttpHeaders: {
				//								Referer: 'http://m.dcloud.io/'
				//							},
				//							videoFullscreen: 'landscape-primary'
				//						});
				//						embed.show("slide-in-right");
				//					} else if(url.startsWith("intent://") || url.startsWith("youku://") || url.startsWith("tenvideo2://")) {
				//
				//					} else {
				//						window.loading = plus.nativeUI.showWaiting("加载中...", {
				//							//							back: "none"
				//						});
				//						homeWebView.loadURL(url)
				//					}
				//
				//				});

			})
		</script>
	</body>

</html>